<%@page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@page import="java.util.Set,java.util.Iterator,com.wubo.sec.model.Menu,com.wubo.bm.SecurityManager" %>
<%@ taglib prefix="s" uri="/struts-tags" %>
<%!
	private boolean isAdmin = SecurityManager.isAdmin();
	private String printMenus(Set<Menu> menus){
		StringBuilder sb = new StringBuilder();
		if(menus != null){
			for(Iterator<Menu> i=menus.iterator(); i.hasNext();){
				Menu m = i.next();
				sb.append("<li id='"+m.getCode()+"' class='jstree-open");
				
				if(m.getSubMenus() != null){
					sb.append("'>");
					if(isAdmin || ! m.isLocked()){
						sb.append("<input type=\"checkbox\" name=\"menuCode\" value=\""+m.getCode()+"\"/>");
					}
					sb.append("<a href='javascript:void(0);'>"+m.getName()+"</a>\n");
					sb.append("<ul>" + printMenus(m.getSubMenus()) + "</ul>\n");
				}else{
					sb.append(" jstree-leaf'>");
					if(isAdmin || ! m.isLocked()){
						sb.append("<input type=\"checkbox\" name=\"menuCode\" value=\""+m.getCode()+"\"/>");
					}
					sb.append("<a href='javascript:void(0);'>"+m.getName()+"</a>\n");
				}
				sb.append("</li>\n");
			}
		}
		return sb.toString();
	}
%>
<s:if test="menuTree != null">
	<s:set value="menuTree" var="list" scope="page"/>
</s:if>

<ul id="tree">
	<%
	out.print( printMenus((Set) pageContext.getAttribute("list")) );
	%>
</ul>